package com.factory.simplefactory.pizzastore.order;

import com.factory.simplefactory.pizzastore.pizzapojo.CheesePizza;
import com.factory.simplefactory.pizzastore.pizzapojo.GreekPizza;
import com.factory.simplefactory.pizzastore.pizzapojo.Pizza;

/**
 * @author 薛虎
 * @date 2020/12/18 9:41
 * 简单工厂类
 * 简单工厂模式改进
 */
public class SimpleFactory {

    //根据orderType 返回对应的Pizza对象
    public static Pizza createPizza(String type) {

        Pizza pizza = null;

        System.out.println("使用简单工厂模式");

        switch (type) {
            case "greek":
                pizza = new GreekPizza();
                pizza.setName("希腊披萨");
                break;

            case "cheese":
                pizza = new CheesePizza();
                pizza.setName("奶酪披萨");
                break;

            default:
                return pizza;
        }

        return pizza;
    }

    //简单工厂模式也叫静态工厂模式
}
